package com.dly.blog.controller;

import cn.hutool.core.util.StrUtil;
import com.dly.blog.annotation.IgnoreAccess;
import com.dly.blog.domain.ro.GetCodeRO;
import com.dly.blog.domain.ro.ParseCodeRO;
import com.dly.blog.enums.FreeType;
import com.dly.blog.exception.ChatExceptionEnum;
import com.dly.blog.msg.R;
import com.dly.blog.service.FreeFrequencyService;
import com.dly.blog.utile.SpringContextHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.core.annotation.Order;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/free")
@Tag(name = "免费次数")
@Slf4j
public class FreeFrequencyController extends BaseController{

    private final FreeFrequencyService freeFrequencyService;

    @Operation(summary = "获取免费的次数code")
    @PostMapping("/code")
    private ResponseEntity<R<String>> getCode(@RequestBody @Valid GetCodeRO getCodeRO, BindingResult br){
        return operate(()-> this.successDate(freeFrequencyService.getCode(getCodeRO)), br);
    }

    @Operation(summary = "解析code")
    @PostMapping("/parseCode")
    @IgnoreAccess
    private ResponseEntity<R<Void>> parseCode(@RequestBody @Valid ParseCodeRO parseCodeRO, BindingResult br){
        validateFiled(br);
        freeFrequencyService.parseCode(parseCodeRO);
        return operate(this::success);
    }
}
